package eol;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringReader;


import eol.compiler.*;
import eol.vm.Machine;

public class BasicTest {    
	static final String newline = String.format("%n") ;
	
    protected String go( String inStr ) {
        System.out.println( "Input is :") ; System.out.println(inStr) ;
        StringReader inReader = new StringReader( inStr ) ; 
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(baos);

        EOLParser parser = new EOLParser( inReader ) ;
        
        parser.m.tracing = false ;
        parser.m.verbose = true ;
        parser.m.setErrorStream(System.out ) ;
        
        parser.m.swapOutputStream( printStream ) ;

        boolean quit ;
        do {
            try {
            	    quit = parser.Item() ; }
            catch( ParseException e ) { 
                printStream.println("Parse Error\n") ;
                printStream.println( e.getMessage() ) ; quit = true ;}
            catch( CompileTimeError e ) {
                printStream.println("Compile Time Error\n") ;
                printStream.println( e.getMessage() ) ; quit = true ; ; }
            catch( Machine.ExecutionError e ) {
                printStream.println("Execution Time Error\n") ;
                printStream.println( e.getMessage() ) ; quit = true ; ; }
            catch( Throwable e ) {
                printStream.println("Error\n") ;
                printStream.println( e.getMessage() ) ; quit = true ; ; }
        } while( ! quit ) ;
        String output = baos.toString() ;
        System.out.println( "Output is: " ) ; System.out.println(output) ;
        return output ;

    }

}
